<?php

namespace App\Helper;

class StaticFile
{
    public static $defaultStaticJSFile = array(
        'jquery1.4' => 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js',
        'yui2.8'    => 'http://ajax.googleapis.com/ajax/libs/yui/2.8.1/build/yuiloader/yuiloader.js',
        'webfont'   => 'http://ajax.googleapis.com/ajax/libs/webfont/1.0.6/webfont_debug.js',
        'kissy1.1'  => 'http://kissyteam.github.com/kissy/build/packages/kissy.js',
        'swfobject' => 'http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject_src.js',
    );

    public static $defaultStaticCSSFile = array(
        'reset' => 'http://kissyteam.github.com/kissy/src/cssreset/reset.css',
    );

    public static function createScript($name, array $attrs = array())
    {
        if (isset(self::$defaultStaticJSFile[$name]))
        {
            return '<script src="' . isset(self::$defaultStaticJSFile[$name]) . '"></script>';
        }

        return '';
    }

    public static function createCss($name, array $attrs = array())
    {
        if (isset(self::$defaultStaticCSSFile[$name]))
        {
            $defaultAttrs = array(
                'rel' => 'stylesheet'
            );
            $attrs = array_merge($defaultAttrs, $attrs);
            foreach ($attrs as $k => $v)
            {
                $attrs[$k] = "$k=\"$v\"";
            }
            return '<link '. implode(' ', $attrs) .' href="' . self::$defaultStaticCSSFile[$name] . '"/>';
        }

        return '';
    }
}